package com.ifdom.collection.eclipsecollections;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.MutableList;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 测试 EclipseCollection 这个工具包
 *
 * @Author ifredomvip@gmail.com
 * @Date 2022/9/21 16:17
 * @Version 1.0.0
 * @Description
 **/
public class EclipseCollectionDemo {
    public static void main(String[] args) {
        MutableList<String> words = Lists.mutable.of((
                "Bah, Bah, black sheep,\n" +
                        "Have you any wool?\n").split("[ ,\n?]+")
        );
        List<String> list = words.toList();
        System.out.println(list);


        withoutEclipseCollection();
        withEclipseCollection();
    }

    /**
     * distinct
     * 不使用 EclipseCollection
     */
    public static void withoutEclipseCollection() {
        ET1 et1 = new ET1("tom1", 18);
        ET1 et2 = new ET1("tom1", 19);
        ET1 et3 = new ET1("tom3", 19);

        List<ET1> collect = Arrays.asList(et1, et2, et3);
        List<String> distinctList = collect.stream().map(ET1::getName).distinct().collect(Collectors.toList());
        System.out.println(distinctList);
    }

    /**
     * distinct
     * 使用 EclipseCollection
     */
    public static void withEclipseCollection() {
        ET1 et1 = new ET1("tom1", 18);
        ET1 et2 = new ET1("tom1", 19);
        ET1 et3 = new ET1("tom3", 19);

        List<String> collect = Lists.mutable.of(et1, et2, et3).collect(ET1::getName).distinct().toList();
        System.out.println(collect);
    }
}
